home *** CD-ROM | disk | FTP | other *** search
/ ShareWare OnLine 2 / ShareWare OnLine Volume 2 (CMS Software)(1993).iso / database / msgobj10.zip / MSGOBJ.H < prev    next >
C/C++ Source or Header  |  1993-03-25  |  9KB  |  299 lines

  1. // MSGOBJ: classes for message handling
  2. #ifndef NODEADDRDEF
  3.   #include "pipbase.h"
  4. #endif
  5.  
  6. // You need the following macros defined for interfacing MessageObject
  7. // with your configuration files
  8. // AREATYPE(area_number)  : 0 for Pip, 1 for Quick, 2 for fido
  9. // AREAPATH(area_number)  : msgbase (or area) path; backslash terminated
  10. // AREATAG(area_number)   : char* to the area echotag (#NETMAIL for netmail
  11. //                          or #LOCAL for local)
  12. // MYZONE   : address of the node where MSGOBJ is running
  13. // MYNET    :
  14. // MYNODE   :
  15. // MYDOMAIN :
  16. // MYFAKENET: (0 if no fakenet is used
  17. // BUFSIZE  : the size of your text buffer, in bytes (30000 is good)
  18. // TEARLINE : your tearline
  19.  
  20. // default definitions are for Pip* 2.0
  21.  
  22. #ifndef AREATYPE
  23.   #define AREATYPE(a) 0
  24. #endif
  25.  
  26. #ifndef AREAPATH
  27.   #ifndef PIPVARS
  28.     #include "pipext.h"
  29.   #endif
  30.   #define AREAPATH(a) cfg.pipdir
  31. #endif
  32.  
  33. #ifndef AREATAG
  34.   #ifndef VIRTUAL_AREAS
  35.     #include "areas.h"
  36.   #endif
  37.   #define AREATAG(a) (areas(a)->tag)
  38. #endif
  39.  
  40. #ifndef MYZONE
  41.   #ifndef PIPVARS
  42.     #include "pipext.h"
  43.   #endif
  44.   #ifndef VIRTUAL_AREAS
  45.     #include "areas.h"
  46.   #endif
  47.   #define MYZONE (cfg.address[areas(area)->address].zone)
  48. #endif
  49.  
  50. #ifndef MYNET
  51.   #ifndef PIPVARS
  52.     #include "pipext.h"
  53.   #endif
  54.   #ifndef VIRTUAL_AREAS
  55.     #include "areas.h"
  56.   #endif
  57.   #define MYNET (cfg.address[areas(area)->address].net)
  58. #endif
  59.  
  60. #ifndef MYNODE
  61.   #ifndef PIPVARS
  62.     #include "pipext.h"
  63.   #endif
  64.   #ifndef VIRTUAL_AREAS
  65.     #include "areas.h"
  66.   #endif
  67.   #define MYNODE (cfg.address[areas(area)->address].node)
  68. #endif
  69.  
  70. #ifndef MYPOINT
  71.   #ifndef PIPVARS
  72.     #include "pipext.h"
  73.   #endif
  74.   #ifndef VIRTUAL_AREAS
  75.     #include "areas.h"
  76.   #endif
  77.   #define MYPOINT (cfg.address[areas(area)->address].point)
  78. #endif
  79.  
  80. #ifndef MYDOMAIN
  81.   #ifndef PIPVARS
  82.     #include "pipext.h"
  83.   #endif
  84.   #ifndef VIRTUAL_AREAS
  85.     #include "areas.h"
  86.   #endif
  87.   #define MYDOMAIN (cfg.address[areas(area)->address].domain)
  88. #endif
  89.  
  90. #ifndef MYFAKENET
  91.   #ifndef PIPVARS
  92.     #include "pipext.h"
  93.   #endif
  94.   #define MYFAKENET (cfg.fakenet)
  95. #endif
  96.  
  97. #ifndef UUCPZONE
  98.   #ifndef PIPVARS
  99.     #include "pipext.h"
  100.   #endif
  101.   #define UUCPZONE (cfg.uucp_out_zone)
  102. #endif
  103.   
  104.  
  105. #ifndef UUCPNET
  106.   #ifndef PIPVARS
  107.     #include "pipext.h"
  108.   #endif
  109.   #define UUCPNET (cfg.uucp_out_net)
  110. #endif
  111.   
  112.  
  113. #ifndef UUCPNODE
  114.   #ifndef PIPVARS
  115.     #include "pipext.h"
  116.   #endif
  117.   #define UUCPNODE (cfg.uucp_out_node)
  118. #endif
  119.   
  120.  
  121. #ifndef TEARLINE
  122.   #ifndef PIPVERSION
  123.     #include "version.h"
  124.   #endif
  125.   #define TEARLINE "Pip*"
  126. #endif
  127.  
  128.  
  129. #ifndef ORIGIN
  130.   #ifndef PIPVARS
  131.     #include "pipext.h"
  132.   #endif
  133.   #ifndef VIRTUAL_AREAS
  134.     #include "areas.h"
  135.   #endif
  136.   #define ORIGIN(a) (origins[areas(a)->origin])
  137. #endif
  138.  
  139.  
  140. #ifndef BUFSIZE
  141.   #define BUFSIZE 30000
  142. #endif
  143.  
  144. // address_class is a class for fidonet and internet addresses
  145.  
  146. class address_class
  147.   {
  148.     friend message_frame;
  149.     public:
  150.       // finds an UUCP address in a netmail message
  151.       int parse_uucp(char*,char*,char*);
  152.       // datas for fidonet addresses
  153.       // zeroes if the address is a pure internet address
  154.       int zone,net,node,point;
  155.       char domain[20];
  156.       // string for uucp addresses; blank if address is pure fidonet
  157.       char uucp[80];
  158.       // parses the string and unpacks it into address fields;
  159.       // returns 0 if successful or -1 otherwise
  160.       int parse(char*);
  161.       // packs the address into a string;
  162.       // returns 0 if successful or -1 otherwise
  163.       int pack(char*);
  164.       address_class(void);
  165.       ~address_class(void);
  166.   };
  167.  
  168.  
  169. class date_time_class
  170.   {
  171.     friend message_frame;
  172.     public:
  173.       // date fields: day, month, year
  174.       int day,month,year;
  175.       // time values: hour, minute, seconds
  176.       int hour,minutes,seconds;
  177.       // parses a  fidonet date (expressed as a string)
  178.       // the date string contains also an hour
  179.       int parse(char*);
  180.       // packs the fields into a FTS-0001 date time
  181.       // returns 0 if successful or -1 otherwise
  182.       int pack(char*);
  183.       date_time_class(void);
  184.       ~date_time_class(void);
  185.   };
  186.  
  187. // IMPORTANT NOTICE: all pointers to message test are huge, to handle 
  188. // messages longer than 64 Kb
  189.  
  190. class message_frame
  191.   {
  192.     // these values are used to handle buffers and dynamic file opening
  193.     int current_area,current_msg;
  194.     // internally used functions
  195.     int open_area(void);
  196.     int close_area(void);
  197.     int pip_msg_post(char huge *,char*,char*,char*,unsigned int,address_class,address_class,int,char*,char*);
  198.     int not_in_seen_by(AUDIT *,unsigned int,unsigned int,unsigned int,int);
  199.     int fileptr,filepkt,filedest;
  200.     char fname[72];
  201.     MSGPKTHDR mpkt;
  202.     MSGPTR hdr;
  203.     #ifdef WIN
  204.       unsigned int textSelector;
  205.     #endif
  206.     public:
  207.       // error code of the last operation
  208.       int lasterror;
  209.       // compresses a string to a file
  210.       // the file has to be opened in binary modeo
  211.       void pipstring(unsigned char huge*,int);
  212.       // decompresses a compressed string to a file, using the first char
  213.       // parameter as CR
  214.       void unpipstring(char,unsigned char huge*,int);
  215.       // decompresses a file to a string
  216.       // the file has to be opened in binary mode
  217.       void unpipfile(unsigned char huge*,int);
  218.       // reads a null terminated string
  219.       int read0(unsigned char huge*,int,unsigned int,char);
  220.       // reads a file (the second pointer is to the file name) into the
  221.       // message buffer pointed by the first parameter, removing LFs
  222.       int readfile(unsigned char huge*,char*);
  223.       // writes a string, null terminated (the NUL is also written to
  224.       // the file)
  225.       void write0(unsigned char huge*,int);
  226.       // writes a text to a file; the third parameter is a character to be
  227.       // used instead of fidonet escape character ^a
  228.       void writemex(unsigned char huge*,int,char);
  229.       // returns a pointer to the origin in the text pointed, or
  230.       // NULL if no origin is found
  231.       char huge*find_origin(char huge*);
  232.       // area number; -1 for no area open
  233.       int area;
  234.       // message number; -1 for no message loaded
  235.       int msg_number;
  236.       // message buffer
  237.       address_class fromaddr,toaddr;
  238.       unsigned int attributes,status;
  239.       unsigned int cost,times;
  240.       char huge*text;
  241.       long textsize; // warning: it's the dimension of the allocated buffer
  242.       char from[36],to[36],subject[72];
  243.       date_time_class date;
  244.       int previous,next; // reply_links
  245.       // all procedures return 0 if successful or -1 otherwise
  246.       // adds the message into the specified area; alters msg_number
  247.       int post(void);
  248.       // modifies the message; if area is changed, the message is
  249.       // forwarded, but the original message is not deleted
  250.       int modify(void);
  251.       // deletes the message pointed by (area,msg_number)
  252.       int del(void);
  253.       // reads into the buffer the message pointed by (area,msg_number);
  254.       // if text==NULL, only the header is loaded;
  255.       // if the parameter is 0 (or if no parameters are passed), message will
  256.       // not be read unless msg_number has changed; pass a nonzero value to
  257.       // force a message reread
  258.       int read(int=0);
  259.       // allocates a buffer in the heap for message text
  260.       int allocate_text(long=BUFSIZE);
  261.       //frees the message in the heap
  262.       int deallocate_text(void);
  263.       // copies seen-bys and path into the specified arrays
  264.       int isolate_seen_by(AUDIT*,int&,int,AUDIT*,int&,int);
  265.       // highest message number in this area; -1 if no area is defined
  266.       int highest_message(void);
  267.       // total number of messages in this area; -1 if no area is defined
  268.       int total_messages(void);
  269.       message_frame(void);
  270.       ~message_frame(void);
  271.   };
  272.  
  273. // error codes returned in lasterror
  274. // no errors
  275. #define MSGERR_NOERR 0
  276. // out of memory
  277. #define MSGERR_ENOMEM -1
  278. // unable to open file
  279. #define MSGERR_ENOFILE -2
  280. // area not selected
  281. #define MSGERR_ENOAREASEL -3
  282. // message not selected 
  283. #define MSGERR_ENOMSGSEL -4
  284. // area not open
  285. #define MSGERR_ENOAREAOPEN -5
  286. // text buffer not allocated
  287. #define MSGERR_ENOBUFFER -6
  288. // msg_number bad: unexisting message
  289. #define MSGERR_ENOMSG -7
  290. // could not write
  291. #define MSGERR_ENOWRITE -8
  292. // could not read
  293. #define MSGERR_ENOREAD -9
  294. // could not reach message
  295. #define MSGERR_ENOSEEK -10
  296.  
  297. // not implemented (in definitive version this code will never be returned)
  298. #define MSGERR_NOTIMPL -128
  299.